package com.zhyt.intelligentpipeline.vo;

import com.zhyt.intelligentpipeline.model.CrackEvaluateModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CrackEvaluateResult {

    private String msg;

    /*评估截至曲线**/
    private double cutOffLineOfEvaluationCurve;

    /**管道的断裂韧性*/
    private double fractureToughness;

    /**韧性比*/
    private double toughnessRatio;

    /*应力强度因子**/
    private double stressIntensityFactor;

    /*载荷比**/
    private double loadRatio;


    public static CrackEvaluateResult getCrackEvaluateResult(CrackEvaluateModel crackEvaluateModel){
        CrackEvaluateResult crackEvaluateResult = new CrackEvaluateResult();
        //设置外径
        crackEvaluateModel.setPipeOutRadius(crackEvaluateModel.getPipeInnerRadius() + crackEvaluateModel.getPipeWallThickness() );
        //获取载荷比
        double loadRatio = CrackEvaluateModel.getLoadRatio(crackEvaluateModel);
        double cutOffLineOfEvaluationCurve  = CrackEvaluateModel.getCutOffLineOfEvaluationCurve(crackEvaluateModel);
        crackEvaluateResult.setCutOffLineOfEvaluationCurve(cutOffLineOfEvaluationCurve);
        crackEvaluateResult.setLoadRatio(loadRatio);
        double toughnessRatio = CrackEvaluateModel.getToughnessRatio(crackEvaluateModel);
        crackEvaluateResult.setToughnessRatio(toughnessRatio);
        if(loadRatio > cutOffLineOfEvaluationCurve){
            //超过了截至线，不需要后续操作，
            crackEvaluateResult.setMsg(WorkingTypeConst.CRACK_NO_SAFE);
            return crackEvaluateResult;
        }
        double K_i = CrackEvaluateModel.getStressIntensityFactor(crackEvaluateModel);
        double standard  = CrackEvaluateModel.getStandard(crackEvaluateModel);
        crackEvaluateResult.setStressIntensityFactor(K_i);
        crackEvaluateResult.setFractureToughness(CrackEvaluateModel.getFractureToughness(crackEvaluateModel));
        if(toughnessRatio < standard){
            crackEvaluateResult.setMsg(WorkingTypeConst.CRACK_SAFE);
        }else{
            crackEvaluateResult.setMsg(WorkingTypeConst.CRACK_NO_SAFE);
        }
        return crackEvaluateResult;
    }
}
